package com.wake.mycomposebook.ui.home.list.my

import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Row
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import com.wake.mycomposebook.ui.home.list.my.horizontal.MyHorizontalList
import com.wake.mycomposebook.ui.home.list.my.vertical.MyGridList
import com.wake.mycomposebook.ui.home.list.my.vertical.MyVerticalList
import com.wake.theme.modifier.MyComposeBookMaterial3Theme

/**
 *@author created by WA03675
 *@date  2022-04-14 16:10
 *@des
 */
class MyListActivity : ComponentActivity() {
    private val isDarkTheme: Boolean by lazy {
        intent.getBooleanExtra(DARK_THEME, false)
    }

    private val listType: String by lazy {
        intent.getStringExtra(LIST_TYPE) ?: ""
    }

    companion object {
        private const val DARK_THEME = "darkTheme"
        private const val LIST_TYPE = "listType"

        fun newIntent(context: Context, isDarkTheme: Boolean, listType: String) {
            val intent = Intent(context, MyListActivity::class.java).apply {
                putExtra(DARK_THEME, isDarkTheme)
                putExtra(LIST_TYPE, listType)
            }
            context.startActivity(intent)
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent { BaseView() }
    }


    @Composable
    fun BaseView() {
        MyComposeBookMaterial3Theme(darkTheme = isDarkTheme) {
            ScreenView()
        }
    }

    /**
     * 如何设置子标题?
     * item 如何分类
     * 如何设置分割线
     *
     */
    @OptIn(ExperimentalMaterial3Api::class)
    @Composable
    fun ScreenView() {
        Scaffold(
            topBar = {
                SmallTopAppBar(
                    title = {
                        Row {
                            IconButton(onClick = { finish() }) {
                                Icon(imageVector = Icons.Default.ArrowBack, contentDescription = null)
                            }
                            Text(text = listType)
                        }
                    },
                )
            },
            content = {

                when (listType) {
                    "Vertical ListView" -> {
                        MyVerticalList()
                    }
                    "Horizontal ListView" -> {
                        MyHorizontalList()
                    }
                    "Grid ListView" -> {
                        MyGridList()
                    }
                    else -> {}
                }
            }
        )
    }


}